﻿using OAuth;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace TestApp
{
    public class Authentication
    {
        public void Run() 
        {

            //Console.WriteLine("Create new instance of OAuth Manager");
            //Manager manager = new Manager(apiKey, secret);

            //Console.WriteLine("Aquire a request token from smugmug");
            //OAuthResponse requestToken = manager.AcquireRequestToken("http://api.smugmug.com/services/oauth/getRequestToken.mg", "GET");

            //string oauthToken = requestToken["oauth_token"];
            //Console.WriteLine(string.Format("oauthToken: {0}", oauthToken));
            //string oauthTokenSecret = requestToken["oauth_token_secret"];
            //Console.WriteLine(string.Format("oauthTokenSecret: {0}", oauthTokenSecret));

            ////Opens your default browser and authorize your request token
            ////Parameters: Access=[Public|Full], Permissions=[Read|Add|Modify]
            //System.Diagnostics.Process.Start(string.Format("http://api.smugmug.com/services/oauth/authorize.mg?oauth_token={0}&Access=Full&Permissions=Modify", oauthToken));

            //Console.WriteLine("Please enter you credentials into the browser before continuing");
            //Console.WriteLine("Press any key to continue...");
            //Console.ReadLine();
    
            //OAuthResponse accessToken = manager.AcquireAccessToken("http://api.smugmug.com/services/oauth/getAccessToken.mg", "GET", oauthTokenSecret);

            //Console.WriteLine(string.Format("accessToken: {0}", accessToken["oauth_token"]));
            //Console.WriteLine(string.Format("accessTokenSecret: {0}", accessToken["oauth_token_secret"]));
            //Console.WriteLine("Press any key to quit the application");
            //Console.ReadLine();
            


        }

        private Tuple<string, string> FetchOAuthSecret()
        {
            try
            {
                var data = File.ReadAllLines(@"C:\smolder.oauth");
                return new Tuple<string, string>(data[0], data[1]);
            }
            catch (Exception e)
            {
                throw new Exception(@"There needs to be a file C:\smolder.oauth containing application oauth information for the application to continue", e);
            }
        }
    }
}
